<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
  <title>JSP - Hello World</title>
</head>
<style>
    div{

    }
</style>
<body>
<h1><%= "欢迎来到注册页面"%></h1>
<br/>
<div>
 用户名： <input type="text" name="username" id="username" placeholder="请输入用户名">
  学号：<input type="text" name="id" id="userid" placeholder="请输入学号">
  密码：<input type="password" name="password" id="pwd" placeholder="请输入密码">
 <button id="btn-register">注册</button>
</div>
</body>

<script src="./static/js/axios.min.js"></script>
<script>
    document.getElementById("btn-register").onclick = function () {
        //点击后获取input框中输入的值
        const username = document.getElementById("username").value;
        const userId = document.getElementById("userid").value;
        const pwd = document.getElementById("pwd").value;
        //发送axios请求
      const url="/user/register";
      const data={
          //存储用户名、学号、密码
          "username":username,
          "id":userId,
          "password":pwd,
      }

        axios.post(url,data).then(function (response) {
            console.log(axios);
              console.log(response);
              if(response.data.code==200){
                  alert(response.data.msg);
                  window.location.href="/login.jsp";
              }else{
                  alert(response.data.msg);
              }
      })
        // axios.get('/register')
        //     .catch(error => {
        //         if (error.response) {
        //             console.log('服务器返回错误状态码:', error.response.status);
        //         }
        //     });


    }
</script>
</html>